package com.itheima.springbootcondition.config;

import com.itheima.springbootcondition.condition.ClassCondition;
import com.itheima.springbootcondition.condition.ConditionOnClass;
import com.itheima.springbootcondition.domain.User;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;

/**
 * 这是user的配置的类
 */

@Configuration
public class UserConfig {

    //创建一个ClassCondition类继承condition重写matches的方法
    @Bean
    //@Conditional(ClassCondition.class)
    @ConditionOnClass("redis.clients.jedis.Jedis")
    public User getUser(){
        return new User();
    }


    //判断配置文件中是否有对应的数据value对应的是key，having value对应的是值
    @Bean
    //@Conditional(ClassCondition.class)
    //@ConditionOnClass("redis.clients.jedis.Jedis")
    @ConditionalOnProperty(value = "itcast",havingValue = "itheima")
    public User getUser2(){
        return new User();
    }
}
